{
  LX Shade module

  Based on modo's SDK lxshade.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012, David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Shade;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_Image, Lx_Vector, Lx_Server;

const
  LXa_TEXTURELAYER                  = 'textureLayer'  ;
  LXa_TEXTUREEVAL                   = 'textureEval'   ;
  LXa_TEXTUREVMAP                   = 'textureVMap'   ;
  LXa_TEXTUREMASK                   = 'textureMask'   ;
  LXa_TEXTUREGL                     = 'textureGL'     ;
  LXa_VALUETEXTURE                  = 'valueTexture'  ;
//LXa_COMPSHADER                    = 'compShader'    ; // Value in SDK 49611
  LXa_COMPSHADER1                   = 'compShader'    ; // Added in SDK 52162
  LXa_COMPSHADER                    = 'compShader2'   ; // Changed in SDK 52162

  LXa_CUSTOMMATERIAL                = 'customMaterial';
  LXa_TEXTURE                       = 'texture'       ;

  LXfPREV_EVENT_MESH                = $01  ;
  LXfPREV_EVENT_ITEM                = $02  ;
  LXfPREV_EVENT_IMAGE               = $04  ;
  LXfPREV_EVENT_CINE                = $08  ;
  LXfPREV_EVENT_MESH_FEATURE        = $10  ;
  LXfPREV_EVENT_MESH_BIN            = $20  ;

  LXfPREV_UPDATE_GEOMETRY           = $01  ;  // geometry change on an entire item
  LXfPREV_UPDATE_SHADING            = $02  ;  // surface shader change
  LXfPREV_UPDATE_BACKDROP           = $04  ;  // environment change
  LXfPREV_UPDATE_IMAGE              = $08  ;  // image edit
  LXfPREV_UPDATE_CAMERA             = $10  ;  // camera change (like during camera navigtion)
  LXfPREV_UPDATE_CLIP               = $20  ;  // clip change
  LXfPREV_UPDATE_LIGHT              = $40  ;  // light item change
  LXfPREV_UPDATE_LIGHT_SHADER       = $80  ;  // light shader change
  LXfPREV_UPDATE_VERTEX_FEATURE     = $100 ;  // vertex feature change in the tableau
  LXfPREV_UPDATE_IRRCACHE           = $200 ;  // irradiance cache change
  LXfPREV_UPDATE_SURFACE            = $400 ;  // geometry change limited to a surface
  LXfPREV_UPDATE_VOLUME             = $8000;  // volume item change
  LXfPREV_UPDATE_FORCE              = $FFFF;  // All flags

  LXi_SURF_ALL                      = 0;
  LXi_SURF_TRIANGLE                 = 1;
  LXi_SURF_FUR                      = 2;

  { Added in SDK 52162 }
  LXfSHADERFLAGS_USE_LOCATOR        = $0001;
  LXfSHADERFLAGS_USE_CLIP           = $0002;
  LXfSHADERFLAGS_USE_LIGHT          = $0004;
  LXfSHADERFLAGS_USE_GROUP          = $0008;
  LXfSHADERFLAGS_NEED_UVS           = $0800;
  { end Added in SDK 52162}

  LXi_TEXTURE_PROJ_MODE_NONE        = 0;
  LXi_TEXTURE_PROJ_MODE_PLANAR      = 1;
  LXi_TEXTURE_PROJ_MODE_CYLINDRICAL = 2;
  LXi_TEXTURE_PROJ_MODE_SPHERICAL   = 3;
  LXi_TEXTURE_PROJ_MODE_CUBIC       = 4;
  LXi_TEXTURE_PROJ_MODE_FRONT       = 5;
  LXi_TEXTURE_PROJ_MODE_UVMAP       = 6;
  LXi_TEXTURE_PROJ_MODE_LIGHTPROBE  = 7;
  LXi_TEXTURE_PROJ_MODE_IMPLICIT    = 8;
  LXi_TEXTURE_PROJ_MODE_BOX         = 9;

  LXi_TEXTURE_PROJ_DIR_X            = 0;
  LXi_TEXTURE_PROJ_DIR_Y            = 1;
  LXi_TEXTURE_PROJ_DIR_Z            = 2;

  LXsTLR_CATEGORY                   = 'textureLayer.category';

  LXu_TEXTURELAYER                  = '{42369FE7-869E-4c61-8D40-AC62E529DD15}';
  LXu_TEXTUREEVAL                   = '{847C1567-1725-4e98-BA09-EA1F9049D76A}';
  LXu_TEXTUREVMAP                   = '{0C68AC79-993C-4823-97FA-EAD5EFF97B64}';
  LXu_TEXTUREMASK                   = '{701E81D3-FFA6-475a-A02D-ECE9AB15B4CD}';
  LXu_TEXTUREGL                     = '{55CE355E-C838-4222-ABED-CBDD808209AF}';
  LXu_VALUETEXTURE                  = '{CA0E3524-6F82-44B8-AAC9-DC258F548C02}';
  LXu_VALUETEXTURECUSTOM            = '{DE3298A6-1607-4338-B061-185528E6FB51}';
//LXu_COMPSHADER                    = '{06717e9d-610d-439f-935b-af0805827ede}'; // Value in SDK 49611
  LXu_COMPSHADER                    = '{371e8b57-3a1e-444b-91f8-5e43c75bf1cb}'; // Changed in SDK 52162
  LXu_COMPSHADER1                   = '{06717e9d-610d-439f-935b-af0805827ede}'; // Added in SDK 52162
//LXu_CUSTOMMATERIAL                = '{d0c4106c-dfd5-4a58-ad48-45b50ae63f59}'; // Value in SDK 49611
  LXu_CUSTOMMATERIAL                = '{64e2dd96-ff7f-4c9b-967e-24dec83bfb72}'; // Changed in SDK 52162
  LXu_CUSTOMMATERIAL1               = '{d0c4106c-dfd5-4a58-ad48-45b50ae63f59}'; // Added in SDK 52162
  LXu_TEXTURE                       = '{6376D941-9437-4cf8-B6EC-AB50791FE60F}';

type
  PPLXtMeshBin = ^PLXtMeshBin;
  PLXtMeshBin  = ^LXtMeshBin ;
  LXtMeshBin   = record   end;

  PLXtPreviewEvent = ^LXtPreviewEvent;
  LXtPreviewEvent  = record
    Flags : Integer ;
    Image : ILxImage;
    Item  ,
    Cine  ,
    Bin   : Pointer ;
    Chan  : Integer ;
  end;

  ILxTextureLayer = interface
  [LXu_TEXTURELAYER]
    function Flags                                       : Integer ;
    function VectorType  (out VObj                     ) : LxResult;
    function Preview     (    Event  : PLXtPreviewEvent) : Integer ;
    function PrepFilter  (    Eval   : IUnknown        ) : LxResult;
    function AllocFilter (    Attr   : IUnknown        ;
                              Offset : PInteger        ;
                              Chan   : Integer         ;
                          out VObj                     ) : LxResult;
    function AllocTexture(    Attr   : IUnknown        ;
                              Offset : Integer         ;
                          out VObj                     ) : LxResult;
  end;

  ILxTextureEval = interface
  [LXu_TEXTUREEVAL]
    function  Setup    (    Slice    : Integer    ) : LxResult;
    procedure Cleanup                               ;
    procedure Evaluate (    VS       : IUnknown   ;
                            Slice    : Integer    ) ;
    procedure Output   (    VTOutput : IUnknown   ;
                            VTSubset : PUnknown   ) ;
    function  Slice    (    VTOutput : IUnknown   ;
                            TVDesc   : IUnknown   ;
                            MeshBin  : PLXtMeshBin;
                            SrfType  : Integer    ) : Integer ;
    procedure Select   (    TEElt    : IUnknown   ;
                            TVDesc   : IUnknown   ;
                            MeshBin  : PLXtMeshBin;
                            SrfType  : Integer    ) ;
    function  Smoothing(    Smooth   : PDouble    ;
                            Angle    : PDouble    ) : Integer ;
    function  Layer    (    Opa      : PDouble    ;
                            Invert   : PInteger   ;
                            Blend    : PInteger   ) : Integer ;
    function  Opaque                                : Integer ;
    function  VType    (out VObj                  ) : LxResult;
    function  Effect   (out VObj                  ) : LxResult;
    function  Item     (    Item     : PPointer   ) : LxResult;
    function  Implicit                              : Integer ;
    function  Shader                                : Integer ;
    function  Material                              : Integer ;
  end;

  ILxTextureVMap = interface
  [LXu_TEXTUREVMAP]
    function Count                          : UInt32  ;
    function Name    (      Index : UInt32;
                      const Name  : PPChar) : LxResult;
    function VMapType(      Index : UInt32) : LXtID4  ;
  end;

  ILxTextureMask = interface
  [LXu_TEXTUREMASK]
    function Tag                                : LXtID4  ;
    function &String   (const Name  : PPChar  ) : LxResult;
    function &Object   (      Item  : PPointer) : LxResult;
    function &Type                              : UInt32  ;
    function Stack     (      Stack : PPointer) : LxResult;
    function ApplyToSub                         : Integer ;
  end;

  ILxTextureGL = interface
  [LXu_TEXTUREGL]
    function Evaluate(Bin : PLXtMeshBin;
                      GLS : Pointer    ) : LxResult;
    function IsShader(Bin : PLXtMeshBin) : Integer ;
  end;

  ILxValueTexture = interface
  [LXu_VALUETEXTURE]
    function  SetupChannels(    AddChan : IUnknown         ) : LxResult;
    function  LinkChannels (    Eval    : IUnknown         ;
                                Item    : IUnknown         ) : LxResult;
    function  ReadChannels (    Attr    : IUnknown         ;
                            out VData                      ) : LxResult;
    function  Customize    (    Custom  : IUnknown         ;
                            out VData                      ) : LxResult;
    procedure Evaluate     (    Vector  : IUnknown         ;
                                TOut    : PLXpTextureOutput;
                                Data    : Pointer          ) ;
    procedure Cleanup      (    Data    : Pointer          ) ;
  end;

  ILxValueTextureCustom = interface
  [LXu_VALUETEXTURECUSTOM]
    function AddFeature(      &Type : LXtID4;
                        const Name  : PChar ) : LxResult;
    function AddPacket (const Name  : PChar ) : LxResult;
  end;

  { Added in SDK 52162 }
  ILxCompShader1 = interface
    function  SetupChannels(      AddChan : IUnknown           ) : LxResult;
    function  LinkChannels (      Eval    : IUnknown           ;
                                  Item    : IUnknown           ) : LxResult;
    function  ReadChannels (      Attr    : IUnknown           ;
                              out VData                        ) : LxResult;
    function  Customize    (      Custom  : IUnknown           ;
                              out VData                        ) : LxResult;
    procedure Evaluate     (      Vector  : IUnknown           ;
                                  RayObj  : IUnknown           ;
                                  SCmp    : PLXpShadeComponents;
                                  SOut    : PLXpShadeOutput    ;
                                  Data    : Pointer            )           ;
    function  SetShadeFlags(      SFlg    : PLXpShadeFlags     ) : LxResult;
    function  SetOpaque    (      Opaque  : PInteger           ) : LxResult;
    function  CustomPacket (const Packet  : PPChar             ) : LxResult;
    procedure Cleanup      (      Data    : Pointer            ) ;
  end;
  { end Added in SDK 52162 }

  ILxCompShader = interface
  [LXu_COMPSHADER]
    function  SetupChannels(      AddChan : IUnknown           ) : LxResult;
    function  LinkChannels (      Eval    : IUnknown           ;
                                  Item    : IUnknown           ) : LxResult;
    function  ReadChannels (      Attr    : IUnknown           ;
                              out VData                        ) : LxResult;
    function  Customize    (      Custom  : IUnknown           ;
                              out VData                        ) : LxResult;
    procedure Evaluate     (      Vector  : IUnknown           ;
                                  RayObj  : IUnknown           ;
                                  SCmp    : PLXpShadeComponents;
                                  SOut    : PLXpShadeOutput    ;
                                  Data    : Pointer            )           ;
    function  SetShadeFlags(      SFlg    : PLXpShadeFlags     ) : LxResult;
    function  SetOpaque    (      Opaque  : PInteger           ) : LxResult;
    function  CustomPacket (const Packet  : PPChar             ) : LxResult;
    procedure Cleanup      (      Data    : Pointer            ) ;
    function  Flags        (                                   ) : Integer ; // Added in SDK 52162
  end;

  { Added in SDK 52162 }
  ILxCustomMaterial1 = interface
  [LXu_CUSTOMMATERIAL]
    function  SetupChannels   (      AddChan       : IUnknown           ) : LxResult;
    function  LinkChannels    (      Eval          : IUnknown           ;
                                     Item          : IUnknown           ) : LxResult;
    function  ReadChannels    (      Attr          : IUnknown           ;
                                 out VData                              ) : LxResult;
    function  Customize       (      Custom        : IUnknown           ;
                                 out VData                              ) : LxResult;
    procedure MaterialEvaluate(      Vector        : IUnknown           ;
                                     Data          : Pointer            ) ;
    procedure ShaderEvaluate  (      Vector        : IUnknown           ;
                                     RayObj        : IUnknown           ;
                                     SCmp          : PLXpShadeComponents;
                                     SOut          : PLXpShadeOutput    ;
                                     Data          : Pointer            ) ;
    function  SetShadeFlags   (      SFlg          : PLXpShadeFlags     ) : LxResult;
    function  SetBump         (      BumpAmplitude : PSingle            ;
                                     ClearBump     : PInteger           ) : LxResult;
    function  SetDisplacement (      DispDist      : PSingle            ) : LxResult;
    function  SetOpaque       (      Opaque        : PInteger           ) : LxResult;
    function  SetSmoothing    (      Smooth        : PDouble            ;
                                     Angle         : PDouble            ) : LxResult;
    function  CustomPacket    (const Packet        : PPChar             ) : LxResult;
    procedure Cleanup         (      Data          : Pointer            ) ;
    function  UpdatePreview   (      ChanIdx       : Integer            ;
                                     Flags         : PInteger           ) : LxResult;
  end;
  { end Added in SDK 52162 }

  ILxCustomMaterial = interface
  [LXu_CUSTOMMATERIAL]
    function  SetupChannels   (      AddChan       : IUnknown           ) : LxResult;
    function  LinkChannels    (      Eval          : IUnknown           ;
                                     Item          : IUnknown           ) : LxResult;
    function  ReadChannels    (      Attr          : IUnknown           ;
                                 out VData                              ) : LxResult;
    function  Customize       (      Custom        : IUnknown           ;
                                 out VData                              ) : LxResult;
    procedure MaterialEvaluate(      Vector        : IUnknown           ;
                                     Data          : Pointer            ) ;
    procedure ShaderEvaluate  (      Vector        : IUnknown           ;
                                     RayObj        : IUnknown           ;
                                     SCmp          : PLXpShadeComponents;
                                     SOut          : PLXpShadeOutput    ;
                                     Data          : Pointer            ) ;
    function  SetShadeFlags   (      SFlg          : PLXpShadeFlags     ) : LxResult;
    function  SetBump         (      BumpAmplitude : PSingle            ;
                                     ClearBump     : PInteger           ) : LxResult;
    function  SetDisplacement (      DispDist      : PSingle            ) : LxResult;
    function  SetOpaque       (      Opaque        : PInteger           ) : LxResult;
    function  SetSmoothing    (      Smooth        : PDouble            ;
                                     Angle         : PDouble            ) : LxResult;
    function  CustomPacket    (const Packet        : PPChar             ) : LxResult;
    procedure Cleanup         (      Data          : Pointer            ) ;
    function  UpdatePreview   (      ChanIdx       : Integer            ;
                                     Flags         : PInteger           ) : LxResult;
    function  Flags           (                                         ) : Integer ;  // Added in SDK 52162
  end;

  ILxTexture = interface
  [LXu_TEXTURE]
    function Locator              (  out VObj              ) : LxResult;
    function SetLocator           (      TLoc    : IUnknown) : LxResult;
    function Image                (  out VObj              ) : LxResult;
    function SetImage             (      Img     : IUnknown) : LxResult;
    function ImageName                                       : PChar   ;
    function EvalImage            (      Scene   : IUnknown  ;
                                     out VObj              ) : LxResult;
    function LocatorProjectionMode(      Time    : Double  ) : Integer ;
    function LocatorProjectionAxis(      Time    : Double  ) : Integer ;
    function Effect                                          : PChar   ;
    function SetEffect            (const Effect_ : PChar   ) : LxResult;
  end;


  { TLxCustomMaterial }

  TLxCustomMaterial = class(TLxServer, ILxCustomMaterial)
    class
    function  GetServerType                               : TGuid   ; override;

    function  SetupChannels
              (      AddChan       : IUnknown           ) : LxResult; virtual ;
    function  LinkChannels
              (      Eval          : IUnknown           ;
                     Item          : IUnknown           ) : LxResult; virtual ;
    function  ReadChannels
              (      Attr          : IUnknown           ;
                 out Data                               ) : LxResult; virtual ;
    function  Customize
              (      Custom        : IUnknown           ;
                 out Data                               ) : LxResult; virtual ;
    procedure MaterialEvaluate
              (      Vector        : IUnknown           ;
                     Data          : Pointer            )           ; virtual ;

    procedure ShaderEvaluate
              (      Vector        : IUnknown           ;
                     RayObj        : IUnknown           ;
                     SCmp          : PLXpShadeComponents;
                     SOut          : PLXpShadeOutput    ;
                     Data          : Pointer            )           ; virtual ;

    function  SetShadeFlags
              (      SFlg          : PLXpShadeFlags     ) : LxResult; virtual ;
    function  SetBump
              (      BumpAmplitude : PSingle            ;
                     ClearBump     : PInteger           ) : LxResult; virtual ;
    function  SetDisplacement
              (      DispDist      : PSingle            ) : LxResult; virtual ;
    function  SetOpaque
              (      Opaque        : PInteger           ) : LxResult; virtual ;
    function  SetSmoothing
              (      Smooth        : PDouble            ;
                     Angle         : PDouble            ) : LxResult; virtual ;
    function  CustomPacket
              (const Packet        : PPChar             ) : LxResult; virtual ;
    procedure Cleanup
              (      Data          : Pointer            ) ;           virtual ;

    function  UpdatePreview
              (      ChanIdx       : Integer            ;
                     Flags         : PInteger           ) : LxResult; virtual ;
    // Added in SDK 52162
    function  Flags                                       : Integer ; virtual ;
  end;

implementation

class
function TLxCustomMaterial.GetServerType: TGuid;
begin
  Result := ILxCustomMaterial;
end;

function TLxCustomMaterial.SetupChannels(AddChan : IUnknown) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.LinkChannels(Eval : IUnknown;
                                        Item : IUnknown) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.ReadChannels(    Attr : IUnknown;
                                        out Data           ) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.Customize(    Custom : IUnknown;
                                     out Data             ) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

procedure TLxCustomMaterial.MaterialEvaluate(Vector : IUnknown;
                                             Data   : Pointer );
begin
end;

procedure TLxCustomMaterial.ShaderEvaluate(Vector : IUnknown           ;
                                           RayObj : IUnknown           ;
                                           SCmp   : PLXpShadeComponents;
                                           SOut   : PLXpShadeOutput    ;
                                           Data   : Pointer            ) ;
begin
end;

function TLxCustomMaterial.SetShadeFlags(SFlg : PLXpShadeFlags) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.SetBump(BumpAmplitude : PSingle ;
                                   ClearBump     : PInteger) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.SetDisplacement(DispDist : PSingle) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.SetOpaque(Opaque : PInteger) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.SetSmoothing(Smooth : PDouble;
                                        Angle  : PDouble) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.CustomPacket(const Packet : PPChar) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

procedure TLxCustomMaterial.Cleanup(Data : Pointer);
begin
end;

function TLxCustomMaterial.UpdatePreview(ChanIdx : Integer ;
                                         Flags   : PInteger) : LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxCustomMaterial.Flags: Integer;
begin
  Result := 0;
end;

end.

